package com.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.beans.Admin;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;


import com.beans.Book;
import com.service.impl.BookServiceImpl;


@Controller
@RequestMapping("/book")
public class BookController {
    @Resource
    BookServiceImpl service;

    @RequestMapping("/getbooks")
    public String get(String userName, ModelMap model) {
        System.out.println("get==>" + userName);
        if (userName != null && !userName.equals("")) {
            List<Book> list = service.getBooks(userName);
            model.addAttribute("list", list);
            return "book/allbook";
        }
        model.addAttribute("error", "未查询到响应的数据，请您检查输入的数据名称是否正确~");
        return "book/allbook";
    }

    /***************** 【以下为修改部分内容】 *********************/
    @RequestMapping("/getallbook")
    public String getallBook() {
        return "book/allbook";
    }

    @RequestMapping("/queryByPage")
    @ResponseBody
    public Map<String, Object> queryByPage(Book book, Integer page, Integer limit) {
        return service.queryByPage(book, page, limit);
    }

    @PostMapping("/gotoupdatebook")
    @ResponseBody
    public Integer updateu(@RequestBody Book book) {
        return  service.updateBook(book);
    }

    @RequestMapping("/deletebook")
    @ResponseBody
    public Integer deleteu(int id) {
        return service.deleteBook(id);
    }

    @RequestMapping("/addbook")
    @ResponseBody
    public Integer addBook(@RequestBody Book book) {
        return service.addBook(book);
    }
}
